package com.ayoka.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Administrator on 2015/7/9.
 */
public class DbHelper extends SQLiteOpenHelper {

    /**
     * 数据库名称 *
     */
    public static final String DATABASE_NAME = "ayoka.db";

    /**
     * 数据库版本 *
     */
    public static final int DATABASE_VERSION = 4;


    /**
     * 创建音乐表*
     */
    private static final String SQL_CREATE_ENTITY_MUSIC = "CREATE TABLE "
            + MusicEntity.TABLE_NAME + " ("
            + MusicEntity.COLUMN_NAME + " TEXT PRIMARY KEY,"
            + MusicEntity.COLUMN_DURATION + " INTEGER NOT NULL,"
            + MusicEntity.COLUMN_SIZE + " LONG NOT NULL)";

    /**
     * 删除音乐表
     */
    private static final String SQL_DELETE_ENTITY_MUSIC = "DROP TABLE IF EXISTS "
            + MusicEntity.TABLE_NAME;


    public DbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_ENTITY_MUSIC);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SQL_DELETE_ENTITY_MUSIC);
        onCreate(db);
    }

    @Override
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        super.onDowngrade(db, oldVersion, newVersion);
    }
}
